<?php
namespace app\admin\model;

use think\Model;

class Recharge extends Model
{
	protected $readonly = ['order'];
	
	public function member(){
		return $this->hasOne('Member','id','user_id');
	}
        
        public function selectInfo($where,$field = '*') {
            $res = $this->where($where)->field($field)->select();
            return empty($res)?array():$res->toArray();
        }
        
        /*
         * 会员充值明细列表
         * @param mixed $where 查询条件
         * @param mixed $startTime 开始时间
         * @param mixed endTime 结束时间
         * @param mixed $page 分页
         * @author cpy(1442435897@qq.com)
         * @return array
         */
        public function memberRechargeDetails($where,$startTime,$endTime,$sort = 'a.id desc',$field = '*') {
            return $this->alias('a')->join('tf_member b','b.id = a.user_id','LEFT')->order($sort)->where($where)->field($field)
                    ->whereTime('a.date','between',[$startTime,$endTime])->paginate('', false, page_param());
        }


    /**
     * 获取充值手续费列表
     * @param $start_time 开始时间
     * @param $end_time 结束时间
     * @author hey_heyang
     * @return  array()
     */
    public function getRcList($start_time,$end_time,$page_size=10,$sort='desc',$type=false){
        if($start_time && $end_time){
            $time1 = strtotime($start_time);
            $time2 = strtotime($end_time.'+ 1 day');
            $condition['gc.date'] = array('between',date('Y-m-d H:i:s',$time1).','.date('Y-m-d H:i:s',$time2));
        }elseif($start_time){
            $condition['gc.date'] = array('eqt',date('Y-m-d H:i:s',strtotime($start_time)));
        }elseif($end_time){
            $condition['gc.date'] = array('elt',date('Y-m-d H:i:s',strtotime($end_time.'+ 1 day')-1));
        }
        $condition['gc.status']=2;
        $field = 'gc.date as time,m.username,m.mobile,gc.fee as money,"充值手续费" as "type"';
        if($type){
            $data=$this->alias('gc')->join('member m','m.id=gc.user_id')->where($condition)->field($field)->order('time '.$sort)->select()->toArray();
        }else{
            $data=$this->alias('gc')->join('member m','m.id=gc.user_id')->where($condition)->field($field)->order('time '.$sort)->paginate($page_size,false,page_param());
        }

        return $data;
    }
        
}